<?php
App::uses('AppModel', 'Model');
/**
 * SysSiteGallery Model
 *
 */
class SysSiteGallery extends AppModel {

/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'title';

/**
 * Validation rules
 *
 * @var array
 */
	public $validate = array(
		'sys_website_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'sys_photo_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'sort' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'description' => array(
				'rule'     => 'notEmpty',
        		'required' => true
		),
		'enable' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	
	/**
	 * belongsTo associations
	 *
	 * @var array
	 */
	public $belongsTo = array(
			'SysPhoto' => array(
					'className' => 'SysPhoto',
					'foreignKey' => 'sys_photo_id',
					'conditions' => '',
					'fields' => '',
					'order' => ''
			),
			'SysWebsite' => array(
					'className' => 'SysWebsite',
					'foreignKey' => 'sys_website_id',
					'conditions' => '',
					'fields' => '',
					'order' => ''
			)
	);
	
	public function getSiteGallery($sys_website_id = null){
		return $this->find('all',array(
				'conditions'=>array(
					'SysSiteGallery.enable'=>1,
					'SysSiteGallery.sys_website_id'=>$sys_website_id,
				),
				'order'=>'SysSiteGallery.sort DESC'
		));
	}
}
